﻿using System.Windows;
using System.Windows.Controls;
using Autorent.Desktop.Main;

namespace Autorent.Desktop
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class Shell : Window
    {
        public Shell()
        {
            InitializeComponent();

            //Show only allowed application tasks by roles
            if (User.IsRole("Manager")) { ManagerTasksShow(); }
            else if (User.IsRole("Administrator")) { AdministratorTasksShow(); }
        }

        public ShellViewModel Model
        {
            get { return DataContext as ShellViewModel; }
            set { DataContext = value; }
        }

        protected void AdministratorTasksShow()
        {
            myOrders.Visibility = System.Windows.Visibility.Collapsed;
            newOrders.Visibility = System.Windows.Visibility.Collapsed;
            allOrders.Visibility = System.Windows.Visibility.Visible;
            clients.Visibility = System.Windows.Visibility.Visible;
            cars.Visibility = System.Windows.Visibility.Visible;
            employees.Visibility = System.Windows.Visibility.Visible;
            offices.Visibility = System.Windows.Visibility.Visible;
            reports.Visibility = System.Windows.Visibility.Visible;
            settings.Visibility = System.Windows.Visibility.Visible;
        }

        protected void ManagerTasksShow()
        {
            myOrders.Visibility = System.Windows.Visibility.Visible;
            newOrders.Visibility = System.Windows.Visibility.Visible;
            allOrders.Visibility = System.Windows.Visibility.Visible;
            clients.Visibility = System.Windows.Visibility.Visible;
            cars.Visibility = System.Windows.Visibility.Visible;
            employees.Visibility = System.Windows.Visibility.Collapsed;
            offices.Visibility = System.Windows.Visibility.Collapsed;
            reports.Visibility = System.Windows.Visibility.Visible;
            settings.Visibility = System.Windows.Visibility.Visible;
        }

        private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //Execute selected application task
            this.Model.SelectTask.Execute(((sender as TabControl).SelectedItem as TabItem).Name);
        }
    }
}
